﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Security.Cryptography;
using Commons.Entity;
using Commons.Entity.CommonEnums;
using System.Transactions;
using Common.Background.Data;
using EF.Commons.Background.Entity;

namespace Common.Background.Service
{
    public partial class SystemServices : ServiceBase
    {
        #region 添加职员
        public void AddWebManageUsers(WebManageUsers WebManageUsers)
        {
            using (TransactionScope trans = new TransactionScope())
            {
                try
                {
                    WebManageUsers.ManageUserID = new PKIDTableRepository().GetNewPKID(PKIDTable.WebManageUsers);
                    WebManageUsers.Operator = string.Empty;
                    WebManageUsers.ManageUserID = new PKIDTableRepository().GetNewPKID(PKIDTable.WebManageUsers);
                    base.iWebManageUsersRepository.Insert(WebManageUsers);
                    trans.Complete();
                }
                catch (Exception)
                {

                    throw;
                }
                finally
                {
                    trans.Dispose();
                }
            }

        }
        #endregion

        #region 修改职员
        public void SetWebManageUsers(WebManageUsers WebManageUsers)
        {
            base.iWebManageUsersRepository.Update(WebManageUsers);
        }
        #endregion

        #region  查询职员
        /// <summary>
        /// 查询职员
        /// </summary>
        /// <param name="WebManageUsers">DepartmentId(是负(全部查),是正(准确查))</param>
        /// RealName，LoginName,是null全部查  
        /// WebManageRoles关联查
        /// <param name="vp"></param>
        /// <param name="pp"></param>
        /// <returns></returns>
        public PagedList<WebManageUsers> WebManageUsersList(WebManageUsers WebManageUsers, VPredication vp, PagingParam pp)
        {
            IQueryable<WebManageUsers> linq = base.iWebManageUsersRepository.GetModel();

            return new PagedList<WebManageUsers>(linq, pp.PageIndex, pp.PageSize);
        }
        #endregion

        #region 删除职员
        public void DeleteWebManageUsers(WebManageUsers WebManageUsers)
        {
            base.iWebManageUsersRepository.Delete(WebManageUsers);
        }
        #endregion

        #region 批量删除职员
        public void DeleteWebManageUsers(List<WebManageUsers> WebManageUsers)
        {
            base.iWebManageUsersRepository.Delete(WebManageUsers);
        }
        #endregion

        #region  冻结职员
        public void FreezeWebManageUsers(List<WebManageUsers> WebManageUsers)
        {
            WebManageUsers.ForEach(item => item.Status = (int)Status.Freezed);
            base.iWebManageUsersRepository.Update(WebManageUsers);
        }
        #endregion

        #region 解冻职员
        public void UnFreezeWebManageUsers(List<WebManageUsers> WebManageUsers)
        {
            WebManageUsers.ForEach(item => item.Status = (int)Status.Normal);
            base.iWebManageUsersRepository.Update(WebManageUsers);
        }
        #endregion

        #region 修改密码[方法作废]
        public void UpdatePassWord(string UserPassword, WebManageUsers WebManageUser)
        {
        }
        #endregion
    }
}